package com.okbihuo.perm.core.tool.jackson;

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import com.okbihuo.perm.core.tool.utils.DateTimeUtil;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * java 8 时间默认序列化
 *
 */
public class MyJavaTimeModule {

	public static JavaTimeModule getMyJavaTimeModule() {
		JavaTimeModule javaTimeModule = new JavaTimeModule();
		javaTimeModule.addSerializer(LocalDateTime.class,new LocalDateTimeSerializer(DateTimeUtil.DATETIME_FORMAT));
		javaTimeModule.addSerializer(LocalDate.class,new LocalDateSerializer(DateTimeUtil.DATE_FORMAT));
		javaTimeModule.addSerializer(LocalTime.class,new LocalTimeSerializer(DateTimeUtil.TIME_FORMAT));
		javaTimeModule.addDeserializer(LocalDateTime.class,new LocalDateTimeDeserializer(DateTimeUtil.DATETIME_FORMAT));
		javaTimeModule.addDeserializer(LocalDate.class,new LocalDateDeserializer(DateTimeUtil.DATE_FORMAT));
		javaTimeModule.addDeserializer(LocalTime.class,new LocalTimeDeserializer(DateTimeUtil.TIME_FORMAT));
		return javaTimeModule;
	}

}
